<template>
    <IDrawer v-model="defaultValue" :loading="loading" :width="860" title="耗材入仓">
        <Form :model="data" :label-width="100" :rules="ruleValidate" ref="formCreate">
            <FormItem label="耗材名称" prop="consumable_id">
                <RemoteSelect url="common/select/consumable" v-model="data.consumable_id" disabled></RemoteSelect>
            </FormItem>
            <FormItem label="耗材成本" prop="type">
                <Select v-model="data.type">
                    <Option :value="0">增加库存</Option>
                    <Option :value="1">核销库存</Option>
                </Select>
            </FormItem>
            <FormItem label="库存" prop="stock">
                <Input v-model="data.stock" number></Input>
            </FormItem>
            <FormItem label="耗材说明" prop="remark">
                <Input v-model="data.remark" type="textarea" :rows="4"></Input>
            </FormItem>
        </Form>
        <div slot="footer">
            <Button type="primary" icon="ios-add" @click="submit('formCreate')">提交</Button>
            <Button type="warning" icon="md-log-out" @click="defaultValue = false">返回</Button>
        </div>
    </IDrawer>
</template>

<script>
    import IForm from "../../../components/content/form";
    import contentDrawer from "../../../mixins/contentDrawer";
    import IDrawer from "../../../components/content/drawer";
    import RemoteSelect from "../../../components/form/remoteSelect";

    export default {
        name: "create",
        mixins: [contentDrawer,],
        components: {RemoteSelect, IForm, IDrawer},
        data() {
            return {
                loading: false,
                data: {consumable_id: this.props.id},
                ruleValidate: {
                    consumable_id: [{required: true, message: "耗材名称"}],
                    type: [{required: true, type:'number', message: "入库类型"}],
                    stock: [{required: true, type:'number', message: "来货库存"}],
                    remark: [{max: 255, message: "备注说明选择"}],
                }
            }
        },
        methods: {
            submit(data) {
                this.validate(data).then(() => {
                    this.loading = true;
                    this.$http.post(`warehouse/consumable_stock`, this.data).then(() => {
                        this.defaultValue = false;
                    }).finally(() => {
                        this.loading = false;
                    });
                });
            }
        }
    }
</script>

<style scoped>

</style>
